/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2022. All rights reserved.
 */

import { Component } from '@ohos/sdkmanager-common';
import path from 'path';

import { ToolChainsConst } from '../../const/sdk-const.js';
import { ArkComponent } from '../superior/ark-component.js';
import { SdkComponent } from '../superior/sdk-component.js';

import { JsArkComponent } from './js-ark-component.js';

/**
 * sdk js实例
 *
 * @since 2021-12-16
 */
export class SdkJsComponent extends SdkComponent {
  private readonly _jsLoaderPath: string;
  private readonly _hapToBinPath: string;
  private readonly _sysCapFilePath: string;

  private arkComponent: ArkComponent;

  constructor(component: Component) {
    super(component);
    this._jsLoaderPath = path.resolve(this.getBaseDir(), 'build-tools', 'ace-loader');
    this._hapToBinPath = path.resolve(this.getBaseDir(), 'build-tools', 'binary-tools', ToolChainsConst.HAP_TO_BIN_TOOL_JAR);
    this._sysCapFilePath = path.resolve(this.getBaseDir(), 'api', 'device-define');
    this.arkComponent = new JsArkComponent(this._jsLoaderPath);
  }

  getJsLoaderPath(): string {
    return this._jsLoaderPath;
  }

  getArkVersion(): string {
    return this.arkComponent.getArkVersion();
  }

  getCompatibleArkVersion(compatibleSdkVersion: number, compatibleSdkVersionStage?: string): string {
    return this.arkComponent.getArkVersion(compatibleSdkVersion, compatibleSdkVersionStage);
  }

  getSysCapFilePath(): string {
    return this._sysCapFilePath;
  }

  getHapToBinFilePath(): string {
    return this._hapToBinPath;
  }
}
